﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using LuKou.Web.View;
using LuKou.Web.Core;

namespace LuKou.Web
{
    public class LuKouWebApplication : System.Web.HttpApplication
    {

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            //网站首页
            routes.MapRoute("WebIndex", "", new { controller = "Home", action = "Index" }, new string[] { "LuKou.Web.Controllers.Website.*" });

            //商品详情
            routes.MapRoute("Goods",
                string.Format("Goods{0}/{{id}}", WebConfig.ExtendName),
                new { controller = "Goods", action = "Index", id = UrlParameter.Optional },
                new string[] { "LuKou.Web.Controllers.Website.*" }
            );

            //店铺路径
            //routes.MapRoute("Store_Index",
            //    string.Format("Store{0}/{{id}}", WebConfig.ExtendName),
            //    new { controller = "Store", action = "Index", id = UrlParameter.Optional },
            //    new string[] { "LuKou.Web.Controllers.Website.*" }
            //);
            //routes.MapRoute("Store",
            //    string.Format("Store{0}/{{action}}/{{id}}", WebConfig.ExtendName),
            //    new { controller = "Store", action = "Index", id = UrlParameter.Optional },
            //    new string[] { "LuKou.Web.Controllers.Website.*" }
            //);

            //默认路由
            routes.MapRoute("Default",
                string.Format("{{controller}}{0}/{{action}}/{{id}}", WebConfig.ExtendName),
                new { controller = "Home", action = "Index", id = UrlParameter.Optional },
                new string[] { "LuKou.Web.Controllers.Website.*" }
            );
        }

        public static void RegisterViewEngines(ViewEngineCollection engines)
        {
            engines.Clear();
            engines.Add(new LuKouViewEngine());
        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterRoutes(RouteTable.Routes);
            RegisterViewEngines(ViewEngines.Engines);
        }
    }
}
